package code.example.zookeeper.base.command.watcher;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NodeCreatedWatcher implements Watcher {
    Logger logger = LoggerFactory.getLogger(NodeCreatedWatcher.class);
    String command = null;
    public NodeCreatedWatcher(String command){
        this.command = command;
    }
    @Override
    public void process(WatchedEvent event) {
        if(event.getState() == Event.KeeperState.SyncConnected){
            if(event.getType() == Event.EventType.NodeCreated){
                String path = event.getPath();
                logger.info("[create][trigger]["+command+"]["+event.getType()+"][watcher]:"+path);
            }else  if(event.getType() == Event.EventType.NodeChildrenChanged){
                String path = event.getPath();
                logger.info("[create][trigger]["+command+"]["+event.getType()+"][watcher]:"+path);
            }
        }
    }
}
